import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

# 读取数据并绘图
n_values = [10, 40, 160]
plt.figure(figsize=(10, 8))

for n in n_values:
    data = pd.read_csv(f'data_F{n}.csv', header=None)  # 指定没有列标题
    x = pd.concat([data[0], pd.Series([data[0].iloc[0]])])
    y = pd.concat([data[1], pd.Series([data[1].iloc[0]])])
    plt.plot(x, y, label=f'n={n}')  # 使用列名（0和1）代替整数索引

# 绘制精确函数
data = pd.read_csv(f'data_F.csv', header=None)  
plt.plot(data[0], data[1], 'k--', label='Exact function')  

# 添加图例和标签
plt.legend()
plt.title('Problem F: curves')
plt.xlabel('x')
plt.ylabel('y')
plt.grid(True)
plt.savefig('F.png') 
plt.show()